Skip to content

Mark non Date/Time objects as invalid - #69

Merged
oriolgual merged 1 commit into
codegram:masterfrom
yez:master
Jan 13, 2016
Merged

oriolgual merged 1 commit into
codegram:masterfrom
yez:master

Conversation

@yez

@yez yez commented Jan 9, 2016

Copy link
Copy Markdown

@oriolgual @txus
This should Resolve #48.

Given a test model:

class TestModel
  attr_accessor :foo
  validates :foo, date: true

  def initialize(date)
    @foo = date
  end
end

Behaviour before this patch:

m = TestModel.new('not a date')
m.valid?
=> true

Behaviour after this patch:

m = TestModel.new('not a date')
m.valid?
=> false

The only outstanding question is should a string like 2016-01-08 go
through Date.parse or to_date to try and make it valid.

This should Resolve codegram#48.

Given a test model:

```ruby
class TestModel
  attr_accessor :foo
  validates :foo, date: true

  def initialize(date)
    @foo = date
  end
end
```

Behaviour before this patch:

```ruby
m = TestModel.new('not a date')
m.valid?
=> true
```

Behaviour after this patch:

```ruby
m = TestModel.new('not a date')
m.valid?
=> false
```

The only outstanding question is should a string like `2016-01-08` go
  through `Date.parse` or `to_date` to try and make it valid.
@oriolgual

Copy link
Copy Markdown
Member

Thanks!

oriolgual added a commit that referenced this pull request Jan 13, 2016
Mark non Date/Time objects as invalid
@oriolgual
oriolgual merged commit da26e6f into codegram:master Jan 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants